#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_soppaccpolar.info <<'%EOF%'
   rsp_soppaccpolar
   ----------------
   Molecule:         CH4
   Wave Function:    CCSD
   Test Purpose:     SOPPA(CCSD) polarizability
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_soppaccpolar.mol <<'%EOF%'
INTGRL
Calculation of SOPPA(CCSD) polarizability

    2    2YZ XZ
        6.    1    2    1    1
C         0.0000000000            0.0000000000            0.000000000
F   8    4
 3623.8613      .0016339191 0.0 0.0 0.0
 544.04621      .012521701 0.0 0.0 0.0
 123.74338      .062113914 0.0 0.0 0.0
 34.763209      .21817729 0.0 0.0 0.0
 10.933333      .49800431 0.0 0.0 0.0
  3.5744765 0.0 1.0 0.0     0.0000000
  .57483245 0.0 0.0 1.0     0.0000000
  .17303640 0.0 0.0 0.0     1.0000000
F   4    2
  9.4432819      .37895451E-01 0.0
  2.0017986      .20818177 0.0
  .54629718      .50474166 0.0
  .15202684 0.0      1.0000000
        1.    1    1    1
H         1.1823709711            1.1823709714            1.1823709713
F   4    2
    13.010701      .019682158 0.0
    1.9622572      .13796524 0.0
    .44453796      .47831935 0.0
    .12194962      0.0 1.0000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_soppaccpolar.dal <<'%EOF%'
**DALTON
.RUN RESPONSE
**WAVE FUNCTION
.HF
.CC
*CC INPUT
.SOPPA(CCSD)
**RESPONSE
.SOPPA(CCSD)
*LINEAR
.FREQUE
 1
 0.000
.DIPLEN
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_soppaccpolar.check
cat >>rsp_soppaccpolar.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "C * 1 * 6\.0000 * 20 * 10 * \[8s4p\|4s2p\]" $log | wc -l`
CRIT2=`$GREP "H * 4 * 1\.0000 * 4 * 2 * \[4s\|2s\]" $log | wc -l`
CRIT3=`$GREP "total\: * 5 * 10\.0000 * 36 * 18" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=3
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 15" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 1\.182370971[0-4]" $log | wc -l`
CRIT6=`$GREP "5 * y * 1\.182370971[0-4]" $log | wc -l`
CRIT7=`$GREP "6 * z * 1\.182370971[0-4]" $log | wc -l`
CRIT8=`$GREP "7 * x * 1\.182370971[0-4]" $log | wc -l`
CRIT9=`$GREP "8 * y * \-1\.182370971[0-4]" $log | wc -l`
CRIT10=`$GREP "9 * z * \-1\.182370971[0-4]" $log | wc -l`
CRIT11=`$GREP "10 * x * \-1\.182370971[0-4]" $log | wc -l`
CRIT12=`$GREP "11 * y * 1\.182370971[0-4]" $log | wc -l`
CRIT13=`$GREP "12 * z * \-1\.182370971[0-4]" $log | wc -l`
CRIT14=`$GREP "13 * x * \-1\.182370971[0-4]" $log | wc -l`
CRIT15=`$GREP "14 * y * \-1\.182370971[0-4]" $log | wc -l`
CRIT16=`$GREP "15 * z * 1\.182370971[0-4]" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16`
CTRL[2]=16
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 4 * 4 * 4" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 6 * 4 * 4 * 4" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# Energies
CRIT1=`$GREP "Total SCF   energy\: * \-40\.170920554." $log | wc -l`
CRIT2=`$GREP "Total MP2   energy\: * \-40\.27892377.." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy\: * \-40\.29926334.." $log | wc -l`
TEST[4]=`expr   $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[4]=6
ERROR[4]="ENERGIES NOT CORRECT"

# SOPPA setup
CRIT1=`$GREP "SOPPA\(CCSD\) \: Second Order Polarization Propagator Approximation" $log | wc -l`
CRIT2=`$GREP "1 second order properties calculated with symmetry no\. * 2 and labels\:" $log | wc -l`
CRIT3=`$GREP "1 second order properties calculated with symmetry no\. * 3 and labels\:" $log | wc -l`
CRIT4=`$GREP "1 second order properties calculated with symmetry no\. * 4 and labels\:" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[5]=4
ERROR[5]="SOPPA(CCSD) SETUP NOT CORRECT"

# Polarizabilities
CRIT3=`$GREP "\@.*XDIPLEN .* XDIPLEN .* 1\.1392705.....(D|E)\+01" $log | wc -l`
CRIT3=`$GREP "\@.*YDIPLEN .* YDIPLEN .* 1\.1392705.....(D|E)\+01" $log | wc -l`
CRIT3=`$GREP "\@.*ZDIPLEN .* ZDIPLEN .* 1\.1392705.....(D|E)\+01" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[6]=3
ERROR[6]="SOPPA(CCSD) POLARIZABILITIES NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
